package com.dotndot.view.list;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class BasicListAdapter extends BaseAdapter
{

    private Context mContext;
    private List<BasicListItem> mArrayList = new ArrayList<BasicListItem>();

    public BasicListAdapter( Context context )
    {
        mContext = context;
    }

    public void addItem( BasicListItem item )
    {
        mArrayList.add(item);
    }

    @Override
    public int getCount()
    {
        return mArrayList.size();
    }

    @Override
    public Object getItem( int position )
    {
        return mArrayList.get(position);
    }

    @Override
    public long getItemId( int position )
    {
        return position;
    }
    
    public void clear(){
        mArrayList.clear();
    }

    @Override
    public View getView( int position, View convertView, ViewGroup parent )
    {
        BasicListLayout itemLayout;

        if( convertView == null )
        {
            Log.e("==gslee==", "=============== BasicListAdapter = create");
            itemLayout = BasicListLayoutFactory.create(mContext, mArrayList.get(position));
        }
        else
        {
            Log.e("==gslee==", "=============== BasicListAdapter = setView");
            itemLayout = (BasicListLayout) convertView;
            itemLayout.setView(mContext, mArrayList.get(position));
        }
        return (View) itemLayout;
    }
}
